package net.lab1024.smartadmin.module.business.engineThousand.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.entity.EngineReverseEntity;
import net.lab1024.smartadmin.module.business.engineThousand.dao.EngineThousandDao;
import net.lab1024.smartadmin.module.business.engineThousand.domain.dto.EngineThousandAddDTO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.dto.EngineThousandUpdateDTO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.dto.EngineThousandQueryDTO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.entity.EngineThousandEntity;
import net.lab1024.smartadmin.module.business.engineThousand.domain.vo.EngineThousandVO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.vo.EngineThousandExcelVO;
import net.lab1024.smartadmin.util.SmartPageUtil;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 发动机万有特性 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 发动机万有特性
 * @copyright (c)  发动机万有特性Inc. All rights reserved.
 * @date 2021-11-07 11:20:13
 * @since JDK1.8
 */
@Service
public class EngineThousandService {

    @Autowired
    private EngineThousandDao engineThousandDao;

    /**
     * 根据id查询
     */
    public EngineThousandEntity getById(Long id){
        return  engineThousandDao.selectById(id);
    }

    public EngineThousandEntity getByEngineId(Long id){
        LambdaQueryWrapper<EngineThousandEntity> queryWrapper = new LambdaQueryWrapper<EngineThousandEntity>();
        queryWrapper.eq(EngineThousandEntity::getEngineId, id);
        return engineThousandDao.selectOne(queryWrapper);
    }


    /**
     * 分页查询
     * @author wuhq
     * @date 2021-11-07 11:20:13
     */
    public ResponseDTO<PageResultDTO<EngineThousandVO>> queryByPage(EngineThousandQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<EngineThousandVO> voList = engineThousandDao.queryByPage(page, queryDTO);
        PageResultDTO<EngineThousandVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2021-11-07 11:20:13
     */
    public ResponseDTO<String> add(EngineThousandAddDTO addDTO) {
        EngineThousandEntity entity = SmartBeanUtil.copy(addDTO, EngineThousandEntity.class);
        engineThousandDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2021-11-07 11:20:13
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(EngineThousandUpdateDTO updateDTO) {
        EngineThousandEntity entity = SmartBeanUtil.copy(updateDTO, EngineThousandEntity.class);
        engineThousandDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2021-11-07 11:20:13
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        engineThousandDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2021-11-07 11:20:13
     */
    public List<EngineThousandExcelVO> queryAllExportData(EngineThousandQueryDTO queryDTO) {
        return engineThousandDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2021-11-07 11:20:13
     */
    public List<EngineThousandExcelVO> queryBatchExportData(List<Long> idList) {
        return engineThousandDao.queryBatchExportData(idList);
    }

    public void delByEngineId(Long engineId) {
        LambdaQueryWrapper<EngineThousandEntity> queryWrapper = new LambdaQueryWrapper<EngineThousandEntity>();
        queryWrapper.eq(EngineThousandEntity::getEngineId, engineId);
        engineThousandDao.delete(queryWrapper);

    }
}
